import java.util.concurrent.*;

public class Thread_1 implements Callable<Integer> {
    public static void main(String[] args) {
        Thread_1 Thread_1 = new Thread_1();
        FutureTask<Integer> future = new FutureTask<>(Thread_1);
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + " 的循环变更i的值" + i);
            if (i == 2) {
                new Thread(future, "有返回的线程").start();
            }
        }
        try {
            System.out.println("子线程的返回值：" + future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    @Override
    public Integer call() throws Exception {
        int i = 0;
        for (; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "" + i);
        }
        return i;
    }
}
